package com.nokia.pc3.core.xform;

import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Iterator;

import com.nokia.pc3.core.dac.NokiaUmem;

/**
 * @author jcroke
 * 
 */
public class Transform {

	private Iterator<Hashtable<String, Object>> xfmIt;
	private Hashtable<String, Object> xfmCurr;
	private NokiaUmem umem;
	private final Xformation xfn;
	protected ArrayList<Hashtable<String, Object>> transformation;

	/**
	 * 
	 * @param xfn
	 *            Xformation dac derived instance containing information about
	 *            the transformation series.
	 * 
	 */
	public Transform(Xformation xfn) {
		this.xfn = xfn;
	}

	/**
	 * Xformation dac derived instance containing information about the
	 * transformation series.
	 * 
	 * @param umem
	 *            NokiaUmem reference to memory used transformation series.
	 * @param xfn
	 *            Xformation DAC derived instance containing information about
	 *            the transformation series.
	 */
	public Transform(NokiaUmem umem, Xformation xfn) {
		this.umem = umem;
		this.xfn = xfn;
	}

	/**
	 * Set the effective transformation series.
	 * 
	 * @param transformation
	 */
	public void setTransformation(
			ArrayList<Hashtable<String, Object>> transformation) {
		this.transformation = transformation;
		xfmIt = transformation.iterator();
	}

	/**
	 * User should call this first before calling next. Queries iterator
	 * instance of parent.
	 * 
	 * @return If there is a next entry.
	 */
	public boolean hasNext() {
		return xfmIt.hasNext();
	}

	/**
	 * Advances iterator, copies to local reference for extended accessor calls.
	 * Returns nothing.
	 */
	public void next() {
		if (xfmIt.hasNext()) {
			xfmCurr = xfmIt.next();
		}
	}

	/**
	 * Get a new iterator.
	 */
	public void reset() {
		xfmIt = transformation.iterator();
	}

	/**
	 * Convience method to return an <@code>instance<@code> of the current
	 * transformer within the transformation series.
	 * 
	 * @return Transformer instance.
	 */
	public Transformer getTransformerInstance() {
		return (Transformer) xfmCurr.get(Xformer.FOBJECT);
	}

	/**
	 * Convience method to return the name of the current transformer within the
	 * transformation series.
	 * 
	 * @return The transformer name.
	 */
	public String getTransformerName() {
		return (String) xfmCurr.get(Xformer.FNAME);
	}

	/**
	 * Convience method to return the input of the current transformer within
	 * the transformation series.
	 * 
	 * @return The transformer input location in local memory.
	 */
	public String getTransformerInput() {
		return (String) xfmCurr.get(Xformer.FINPUT);
	}

	/**
	 * Convience method to return the output of the current transformer within
	 * the transformation series.
	 * 
	 * @see NokiaUmem
	 * @return The transformer output location in local memory.
	 */
	public String getTransformerOutput() {
		return (String) xfmCurr.get(Xformer.FOUTPUT);
	}

	/**
	 * Convience method to return the arguments of the current transformer
	 * within the transformation series.
	 * 
	 * @see NokiaUmem
	 * @return The optional argument string of the transformer.
	 */
	public String getTransformerArg() {
		return (String) xfmCurr.get(Xformer.FARGS);
	}

	/**
	 * Convience method to return the output labels of the current transformer
	 * within the transformation series.
	 * 
	 * @see NokiaUmem
	 * @return The labels string of the transformer.
	 */
	public String getTransformerLabels() {
		return (String) xfmCurr.get(Xformer.FLABELS);
	}

	/**
	 * Convienience method for getting memory instance applied to this
	 * transformation.
	 * 
	 * @return Reference to NokiaUmem object used by Transformers within this
	 *         Transform container.
	 * 
	 */
	public NokiaUmem getTransformUmem() {
		return umem;
	}

	/**
	 * Convienience method for setting memory instance applied to this
	 * transformation.
	 * 
	 * @return Reference to NokiaUmem object used by Transformers within this
	 *         Transform container.
	 * 
	 */
	public void setTransformUmem(NokiaUmem umem) {
		this.umem = umem;
	}

	/**
	 * Convienience method.
	 * 
	 * @return Reference to Xformation object.
	 * 
	 */
	public Xformation getXformation() {
		return xfn;
	}

}
